//
// Created by sgyt on 2020/6/1.
// 获取协议名字和协议编号

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>

void printf_port(struct protoent *pProtoent);

int main(int argc, char *argv[])
{
    struct protoent *port;

    setprotoent(1);

    while((port = getprotoent()) != NULL)
    {
        printf_port(port);
        printf("\n");
    }

    endprotoent();
    return 0;
}

void printf_port(struct protoent *pProtoent) {
    char **aliase;

    printf("port name is %s\n",pProtoent->p_name);

    for(aliase = pProtoent->p_aliases;*aliase;aliase++)
    {
        printf("aliase is %s\n",*aliase);
    }

    printf("proto is %d\n",pProtoent->p_proto);
}
